package com.fortune.cat.resolver;

import org.springframework.web.server.ServerWebExchange;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaozeyang
 * @date 2019/4/26 12:14
 * @description
 */
public class CompositeKeyResolver extends AbstractKeyResolver {

    private final Map<Integer, AbstractKeyResolver> keyResolverMap = new HashMap<>();

    public CompositeKeyResolver(List<AbstractKeyResolver> keyResolvers) {
        keyResolvers.forEach(resolver -> keyResolverMap.put(resolver.getType(), resolver));
    }

    @Override
    public Integer getType() {
        return 0;
    }

    @Override
    protected String doResolve(ServerWebExchange exchange) {
        AbstractKeyResolver resolver = keyResolverMap.get(requestRateLimiterConfig.getKeyResolverType());
        return resolver.doResolve(exchange);
    }
}
